home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / uucp / protocol / chesson.paper < prev    next >
Encoding:
Internet Message Format  |  1991-08-18  |  17.0 KB

  1. Path: clarkson!rpi!sarah!cs.albany.edu!psinntp!iggy.GW.Vitalink.COM!lll-winken!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!ucsd!nosc!crash!simpact!cmkrnl!jeh
  2. From: jeh@cmkrnl.uucp
  3. Newsgroups: comp.mail.uucp
  4. Subject: Re: G protocol (Chesson paper)
  5. Message-ID: <1991Aug4.160256.191@cmkrnl.uucp>
  6. Date: 4 Aug 91 23:02:56 GMT
  7. References: <4682@se-sd.SanDiego.NCR.COM> <231@s5000.rsvl.unisys.com> <1991Aug2.012529.10008@uunet.uu.net>
  8. Organization: Kernel Mode Consulting, San Diego CA
  9. Lines: 532
  10.  
  11. The paper on the "G" Protocol which I just posted references articles
  12. by Greg Chesson and Chuck Wegrzyn.  Here is the Chesson paper.  
  13.  
  14.  
  15.                    _P_a_c_k_e_t _D_r_i_v_e_r _P_r_o_t_o_c_o_l
  16.  
  17.                        G. L. Chesson
  18.                      Bell Laboratories
  19.  
  20. _A_b_s_t_r_a_c_t
  21.  
  22.           These notes describe the packet driver link proto-
  23.      col that was supplied with the Seventh Edition of UNIX*
  24.      and is used by the UUCP program.
  25.  
  26. _G_e_n_e_r_a_l
  27.  
  28.      Information flow between a  pair  of  machines  may  be
  29. regulated  by  first  representing  the  data  as  sequence-
  30. numbered _p_a_c_k_e_t_s of data and then  establishing  conventions
  31. that  govern the use of sequence numbers.  The _P_K, or _p_a_c_k_e_t
  32. _d_r_i_v_e_r, protocol is a particular instance of  this  type  of
  33. flow-control  discipline.   The  technique  depends  on  the
  34. notion of a transmission _w_i_n_d_o_w to determine upper and lower
  35. bounds  for  valid  sequence  numbers.   The  transmitter is
  36. allowed to retransmit packets having sequence numbers within
  37. the  window  until  the receiver indicates that packets have
  38. been correctly received.  Positive acknowledgement from  the
  39. receiver  moves  the  window; negative acknowledgement or no
  40. acknowledgement causes retransmission.   The  receiver  must
  41. ignore  duplicate  transmission,  detect  the various errors
  42. that may occur, and inform the transmitter when packets  are
  43. correctly or incorrectly received.
  44.  
  45.      The following paragraphs describe the  packet  formats,
  46. message exchanges, and framing used by the protocol as coded
  47. in the UUCP  program  and  the  UNIX  kernel.   Although  no
  48. attempt will be made here to present internal details of the
  49. algorithms that were used, the checksum routine is  supplied
  50. for the benefit of other implementors.
  51.  
  52. _P_a_c_k_e_t _F_o_r_m_a_t_s
  53.  
  54.      The protocol is defined in terms of  message  transmis-
  55. sions  of  8-bit  bytes.   Each message includes one _c_o_n_t_r_o_l
  56. byte plus a _d_a_t_a _s_e_g_m_e_n_t of zero or more information  bytes.
  57. The  allowed data segment sizes range between 32 and 4096 as
  58. determined by the formula 32(28k9) where k is a 3-bit  number.
  59. The  packet  sequence numbers are likewise constrained to 3-
  60. bits; i.e. counting proceeds modulo-8.
  61.  
  62.      The control byte is partitioned into  three  fields  as
  63. depicted below.
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. __________________________
  72. *UNIX is a Trademark of AT&T Bell Laboratories.
  73.  
  74.  
  75.  
  76.  
  77.                       October 5, 1988
  78.  
  79.  
  80.  
  81.  
  82.  
  83.                            - 2 -
  84.  
  85.  
  86.           bit  7    6    5    4    3    2    1    0
  87.                t    t    x    x    x    y    y    y
  88.  
  89. The  _t  bits  indicate  a  packet  type  and  determine  the
  90. interpretation  to be placed on the _x_x_x and _y_y_y fields.  The
  91. various interpretations are as follows:
  92.  
  93.           _t_t   _i_n_t_e_r_p_r_e_t_a_t_i_o_n
  94.  
  95.           00   control packet
  96.           10   data packet
  97.           11   `short' data packet
  98.           01   alternate channel
  99.  
  100. A data segment accompanies all  non-control  packets.   Each
  101. transmitter  is constrained to observe the maximum data seg-
  102. ment size established during initial synchronization by  the
  103. receiver  that  it  sends  to.  Type 10 packets have maximal
  104. size data segments.  Type 11, or `short', packets have  zero
  105. or more data bytes but less than the maximum.  The first one
  106. or two bytes of the data  segment  of  a  short  packet  are
  107. `count'  bytes that indicate the difference between the max-
  108. imum size and the number of bytes in the short segment.   If
  109. the difference is less than 127, one count byte is used.  If
  110. the difference exceeds 127, then the low-order seven bits of
  111. the  difference are put in the first data byte and the high-
  112. order bit is set as an indicator that the remaining bits  of
  113. the  difference are in the second byte.  Type 01 packets are
  114. never used by UUCP and need not be discussed in detail here.
  115.  
  116.      The sequence number of a non-control packet is given by
  117. the  _x_x_x  field.   Control  packets  are not sequenced.  The
  118. newest sequence number, excluding  duplicate  transmissions,
  119. accepted  by  a  receiver is placed in the _y_y_y field of non-
  120. control packets sent to the `other' receiver.
  121.  
  122.      There are no  data  bytes  associated  with  a  control
  123. packet,  the  _x_x_x field is interpreted as a control message,
  124. and the _y_y_y field is a value accompanying the  control  mes-
  125. sage.   The  control messages are listed below in decreasing
  126. priority.  That is, if several control messages  are  to  be
  127. sent, the lower-numbered ones are sent first.
  128.  
  129.           _x_x_x  _n_a_m_e      _y_y_y
  130.  
  131.           1    CLOSE     n/a
  132.           2    RJ        last correctly received sequence number
  133.           3    SRJ       sequence number to retransmit
  134.           4    RR        last correctly received sequence number
  135.           5    INITC     window size
  136.           6    INITB     data segment size
  137.           7    INITA     window size
  138.  
  139.  
  140.  
  141.  
  142.  
  143.                       October 5, 1988
  144.  
  145.  
  146.  
  147.  
  148.  
  149.                            - 3 -
  150.  
  151.  
  152.      The CLOSE message  indicates  that  the  communications
  153. channel  is  to  be  shut  down.  The RJ, or _r_e_j_e_c_t, message
  154. indicates that the receiver has detected an  error  and  the
  155. sender should retransmit after using the _y_y_y field to update
  156. the window.  This mode of retransmission is usually referred
  157. to  as  a  `go-back-N'  procedure.   The  SRJ,  or _s_e_l_e_c_t_i_v_e
  158. _r_e_j_e_c_t, message carries with it the  sequence  number  of  a
  159. particular  packet to be retransmitted.  The RR, or _r_e_c_e_i_v_e_r
  160. _r_e_a_d_y, message indicates that the receiver has  detected  no
  161. errors;  the  _y_y_y  field  updates  the sender's window.  The
  162. INITA/B/C messages are used to set window and  data  segment
  163. sizes.  Segment sizes are calculated by the formula 32(28yyy9)
  164. as mentioned above, and window sizes may range between 1 and
  165. 7.
  166.  
  167.      Measurements of the protocol running  on  communication
  168. links  at rates up to 9600 baud showed that a window size of
  169. 2 is optimal given a packet  size  greater  than  32  bytes.
  170. This  means that the link bandwidth can be fully utilized by
  171. the software.  For this reason the SRJ  message  is  not  as
  172. important  as  it  might  otherwise  be.  Therefore the UNIX
  173. implementations no longer generate or respond  to  SRJ  mes-
  174. sages.   It  is mentioned here for historical accuracy only,
  175. and one may assume that SRJ is no longer part of the  proto-
  176. col.
  177.  
  178. _M_e_s_s_a_g_e _E_x_c_h_a_n_g_e_s
  179.  
  180.      _I_n_i_t_i_a_l_i_z_a_t_i_o_n
  181.  
  182.      Messages are exchanged between four  cooperating  enti-
  183. ties:  two  senders  and two receivers.  This means that the
  184. communication channel  is  thought  of  as  two  independent
  185. half-duplex  data paths.  For example the window and segment
  186. sizes need not be the same in each direction.
  187.  
  188.      Initial synchronization is accomplished with two  3-way
  189. handshakes:  two  each  of  INITA/INITB/INITC.   Each sender
  190. transmits INITA messages repeatedly.  When an INITA  message
  191. is received, INITB is sent in return.  When an INITB message
  192. is received _a_n_d an INITB message has  been  sent,  an  INITC
  193. message  is  sent.   The INITA and INITB messages carry with
  194. them the packet and window size that each receiver wants  to
  195. use,  and  the  senders  are  supposed  to  comply.   When a
  196. receiver has seen all three INIT messages,  the  channel  is
  197. considered to be open.
  198.  
  199.      It is possible to design  a  protocol  that  starts  up
  200. using   fewer   messages  than  the  interlocked  handshakes
  201. described above.  The  advantage  of  the  more  complicated
  202. design  lies  in  its use as a research vehicle: the initial
  203. handshake sequence is completely symmetric, a handshake  can
  204. be initiated by one side of the link while the connection is
  205. in use, and the software to do this can  utilize  code  that
  206.  
  207.  
  208.  
  209.                       October 5, 1988
  210.  
  211.  
  212.  
  213.  
  214.  
  215.                            - 4 -
  216.  
  217.  
  218. would ordinarily be used only once at connection setup time.
  219. These properties were used in experiments  with  dynamically
  220. adjusted  parameters.   That  is attempts were made to adapt
  221. the window and segment sizes to changes observed in  traffic
  222. while a link was in use.  Other experiments used the initial
  223. handshake  in a different way for  restarting  the  protocol
  224. without  data loss after machine crashes.  These experiments
  225. never worked well in the packet driver  and  basically  pro-
  226. vided the impetus for other protocol designs.  The result as
  227. far as UUCP is concerned  is  that  initial  synchronization
  228. uses  the  two  3-way  handshakes, and the INIT messages are
  229. ignored elsewhere.
  230.  
  231.      _D_a_t_a _T_r_a_n_s_p_o_r_t
  232.  
  233.      After initial  synchronization  each  receiver  sets  a
  234. modulo-8  incrementing  counter  R  to 0; each sender sets a
  235. similar counter S to 1.  The value of R is always the number
  236. of  the most recent correctly received packet.  The value of
  237. S is always the first sequence number in the output  window.
  238. Let  W  denote window size.  Note that the value of W may be
  239. different for each sender.
  240.  
  241.      A sender may transmit packets with sequence numbers  in
  242. the  range  S  to  (S+W-1) mod-8.   At any particular time a
  243. receiver expects arriving packets to  have  numbers  in  the
  244. range  (R+1) mod-8  to  (R+W) mod-8.  Packets must arrive in
  245. sequence number order are are only  acknowledged  in  order.
  246. That  is, the `next' packet a receiver will acknowledge must
  247. have sequence number (R+1) mod-8.
  248.  
  249.      A receiver acknowledges  receipt  of  data  packets  by
  250. arranging  for  the value of its R counter to be sent across
  251. the channel where it will be used to update  an  S  counter.
  252. This is done in two ways.  If data is flowing in both direc-
  253. tions across a channel then each receiver's current R  value
  254. is  carried in the _y_y_y field of non-control packets.  Other-
  255. wise  when  there  is  no  bidirectional  data  flow,   each
  256. receiver's R value is transmitted across the link as the _y_y_y
  257. field of an RR control packet.
  258.  
  259.      Error handling is up to the discretion of the receiver.
  260. It  can ignore all errors in which case transmitter timeouts
  261. must provide for retransmission.  The receiver may also gen-
  262. erate  RJ error control packets.  The _y_y_y field of an incom-
  263. ing RJ message replaces the S value of the local sender  and
  264. constitutes  a  request  for retransmission to start at that
  265. sequence number.  The _y_y_y field of an incoming  SRJ  message
  266. selects a particular packet for retransmission.
  267.  
  268.      The resemblance between the flow control  procedure  in
  269. the  packet driver and that defined for X.25 is no accident.
  270. The packet driver protocol  began  life  as  an  attempt  at
  271. cleaning  up  X.25.   That  is  why,  for  example,  control
  272.  
  273.  
  274.  
  275.                       October 5, 1988
  276.  
  277.  
  278.  
  279.  
  280.  
  281.                            - 5 -
  282.  
  283.  
  284. information is uniform in length (one byte), there is no RNR
  285. message  (not  needed), and there is but one timeout defined
  286. in the sender.
  287.  
  288.      _T_e_r_m_i_n_a_t_i_o_n
  289.  
  290.      The CLOSE message is used to terminate  communications.
  291. Software on either or both ends of the communication channel
  292. may initiate termination.  In any case when one end wants to
  293. terminate it sends CLOSE messages until one is received from
  294. the other end or until a programmable limit on the number of
  295. CLOSE  messages  is  reached.   Receipt  of  a CLOSE message
  296. causes a CLOSE message to be sent.  In the UNIX  environment
  297. it  also  causes  the  SIGPIPE or `broken pipe' signal to be
  298. sent to the local process using the communication channel.
  299.  
  300.      _F_r_a_m_i_n_g
  301.  
  302.      The term _f_r_a_m_i_n_g is used to  denote  the  technique  by
  303. which  the  beginning  and end of a message is detected in a
  304. byte stream; _e_r_r_o_r  _c_o_n_t_r_o_l  denotes  the  method  by  which
  305. transmission  errors  are  detected.  Strategies for framing
  306. and error control depend upon additional  information  being
  307. transmitted  along  with  the control byte and data segment,
  308. and the choice of a particular strategy usually  depends  on
  309. characteristics  of  input/output  devices  and transmission
  310. media.
  311.  
  312.      Several framing techniques are in used in support of PK
  313. protocol  implementations, not all of which can be described
  314. in detail here.  The technique used on  asynchronous  serial
  315. lines will be described.
  316.  
  317.      A six byte framing _e_n_v_e_l_o_p_e is  constructed  using  the
  318. control  byte C of a packet and five other bytes as depicted
  319. below.
  320.           <DLE><k><c0><c1><C><x>
  321. The <DLE> symbol denotes the ASCII ctrl/P character.  If the
  322. envelope  is  to  be followed by a data segment, <k> has the
  323. value log928(size)-4; i.e. 1 <_ k <_ 8.  If k  is  9,  then  the
  324. envelope  represents  a  control  packet.  The <c0> and <c1>
  325. bytes are the low-order and high-order bytes respectively of
  326. 0xAAAA  minus  a 16-bit checksum.  For control packets, this
  327. 16-bit checksum is the same as the control byte C.  For data
  328. packets,  the  checksum  is calculated by the program below.
  329. The <x> byte is the exclusive-or of  <k><c0><c1><C>.   Error
  330. control  is  accomplished  by  checking  a  received framing
  331. envelope for compliance with the definition, and comparing a
  332. checksum function of the data segment with <c0><c1>.
  333.  
  334.      This particular framing strategy assumes data  segments
  335. are constant-sized: the `unused' bytes in a short packet are
  336. actually transmitted.  This  creates  a  certain  amount  of
  337. overhead  which  can  be  eliminated  by  a more complicated
  338.  
  339.  
  340.  
  341.                       October 5, 1988
  342.  
  343.  
  344.  
  345.  
  346.  
  347.                            - 6 -
  348.  
  349.  
  350. framing technique.  The advantage of this strategy  is  that
  351. i/o  devices  can  be  programmed  to  take advantage of the
  352. constant-sized framing envelopes and data segments.
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.                       October 5, 1988
  408.  
  409.  
  410.  
  411.  
  412.  
  413.                            - 7 -
  414.  
  415.  
  416.      The checksum calculation is  displayed  below  as  a  C
  417. function.   Note that the code is not truly portable because
  418. the definitions of _s_h_o_r_t and _c_h_a_r are not  necessarily  uni-
  419. form  across  all machines that might support this language.
  420. This code assumes that _s_h_o_r_t and  _c_h_a_r  are  16  and  8-bits
  421. respectively.
  422.  
  423.      /* [Original document's version corrected to actual version] */
  424.      chksum(s,n)
  425.      register char *s;
  426.      register n;
  427.      {
  428.           register short sum;
  429.           register unsigned short t;
  430.           register short x;
  431.  
  432.           sum = -1;
  433.           x = 0;
  434.  
  435.           do {
  436.                if (sum<0) {
  437.                     sum <<= 1;
  438.                     sum++;
  439.                } else
  440.                     sum <<= 1;
  441.                t = sum;
  442.                sum += (unsigned)*s++ & 0377;
  443.                x += sum^n;
  444.                if ((unsigned short)sum <= t) {
  445.                     sum ^= x;
  446.                }
  447.           } while (--n > 0);
  448.  
  449.           return(sum);
  450.      }
  451.  
  452. The checksum routine used in  gnuucp  has  been  updated  to
  453. avoid  depending  on  the particular sizes of _c_h_a_r and _s_h_o_r_t
  454. variables.  As long as a _c_h_a_r holds 8 bits or  more,  and  a
  455. _s_h_o_r_t  holds  16  bits or more, the code will work.  To test
  456. it, uncomment the ``#define short long'' below.  A good com-
  457. piler  produces the same code from this function as from the
  458. less portable version.
  459.  
  460.      #define   HIGHBIT16 0x8000
  461.      #define   JUST16BITS     0xFFFF
  462.      #define   JUST8BITS 0x00FF
  463.      #define   MAGIC          0125252        /* checksum is subtracted from this */
  464.  
  465.      int
  466.      pktchksum(msg, bytes)
  467.           unsigned char *msg;
  468.           int bytes;
  469.      {
  470.  
  471.  
  472.  
  473.                       October 5, 1988
  474.  
  475.  
  476.  
  477.  
  478.  
  479.                            - 8 -
  480.  
  481.  
  482.           return (JUST16BITS &
  483.                (MAGIC - (chksum(&msg[6], bytes) ^ (JUST8BITS & msg[4]))));
  484.  
  485.      }
  486.  
  487.  
  488.      int
  489.      chksum(s,n)
  490.      register unsigned char *s;
  491.      register n;
  492.      {
  493.      /* #define short long    /* To make sure it works with shorts > 16 bits */
  494.           register short sum;
  495.           register unsigned short t;
  496.           register short x;
  497.  
  498.           sum = (-1) & JUST16BITS;
  499.           x = 0;
  500.           do {
  501.                /* Rotate "sum" left by 1 bit, in a 16-bit barrel */
  502.                if (sum & HIGHBIT16)
  503.                {
  504.                     sum = (1 + (sum << 1)) & JUST16BITS;
  505.                }
  506.                else
  507.                     sum <<= 1;
  508.                t = sum;
  509.                sum = (sum + (*s++ & JUST8BITS)) & JUST16BITS;
  510.                x += sum ^ n;
  511.                if ((unsigned short)sum <= t)
  512.                     sum = (sum ^ x) & JUST16BITS;
  513.           } while (--n > 0);
  514.  
  515.           return(sum);
  516.      #undef short        /* End of debugging check */
  517.      }
  518.  
  519. Volume-Number: Volume 14, Number 13
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.                       October 5, 1988
  540.  
  541.  
  542. (end)
  543.